home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 42
/
Amiga Format AFCD42 (Issue 126, Aug 1999).iso
/
-serious-
/
emulation
/
amigavgb_ppc
/
demos
/
space.s
< prev
next >
Wrap
Text File
|
1999-05-17
|
36KB
|
1,294 lines
; Little demo illustrating how to use the graphical possibilities
; of the GB (background, window and animated sprite).
; I have used fixed-point values for both the position and
; speed of objects to get smooth movements.
;
; OBJ data : 0x8000 -> 0x8FFF (unsigned).
; Window data : 0x8800 -> 0x97FF (unsigned).
; Background data : 0x8800 -> 0x97FF (signed).
;
; Tiled 0xFC -> 0xFF are standard tiles (all black -> all white).
;
; Keys:
; Directions : Change the speed (and direction) of the sprite
; Directions + A : Change the speed (and direction) of the window
; Directions + B : Change the speed (and direction) of the background
; START : Open/close the door
; SELECT : Basic fading effect
;
; Note that the window is kept in the lower right part of the screen
; since it can't be made transparent.
.include "lib/global.h"
.DELAY = 0x1000 ; Delay value to slow the animation
.NBDFRAMES = .endfilm-.film ; Nb frames for the door
.NBSFRAMES = 0x07 ; Nb frames for the sprite
.WINSZX = 0x80 ; Size of the picture in the window
.WINSZY = 0x50
.MINWINX = .MAXWNDPOSX-.WINSZX+1 ; Bounds of the window origin
.MINWINY = .MAXWNDPOSY-.WINSZY+1
.MAXWINX = .MAXWNDPOSX
.MAXWINY = .MAXWNDPOSY
.FADESTEP = 0x10 ; Nb steps for the fading effect
.STARTFADE = 0x06*.FADESTEP ; Initial value for the fading effect
.module Demo
.area _BSS
.time: ; Global "time" value (counter)
.ds 0x01
.doorstate: ; State of the door (OPENED, CLOSED...)
.ds 0x01
.doorpos: ; Current position in the door animation
.ds 0x01
.color: ; Current color for fading effect
.ds 0x01
.sframe: ; Current frame of the sprite
.ds 0x01
.bposx:
.ds 0x02 ; Background position (fixed point)
.bposy:
.ds 0x02
.bspx:
.ds 0x02 ; Background speed (fixed point)
.bspy:
.ds 0x02
.wposx:
.ds 0x02 ; Window position (fixed point)
.wposy:
.ds 0x02
.wspx:
.ds 0x02 ; Window speed (fixed point)
.wspy:
.ds 0x02
.sposx:
.ds 0x02 ; Sprite position (fixed point)
.sposy:
.ds 0x02
.sspx:
.ds 0x02 ; Sprite speed (fixed point)
.sspy:
.ds 0x02
.area _CODE
.CLOSED = 0x00
.OPENING = 0x01
.OPENED = 0x02
.CLOSING = 0x03
_main::
DI ; Disable interrupts
CALL .wait_vbl ; Must be in VBL before turning the screen off.
LD A,#0b01100111 ; LCD = Off (no picture on screen)
LDH (.LCDCONT),A
; WindowBank = 0x9C00
; Window = On
; BG Chr = 0x8800
; BG Bank = 0x9800
; OBJ = 8x16
; OBJ = On
; BG = On
LD A,#0b11100100
LDH (.BGRDPAL),A
LDH (.SPR0PAL),A
XOR A ; A = 0
LD (.time),A
LD (.color),A
; Initialize tiles
LD B,#0x00
CALL .init_tiles ; Init the tile set at 0x8000 with 0x00
LD B,#0xFF
CALL .init_btt ; Init the tiles tables with 0xFF
CALL .init_wtt
LD BC,#.tp0
LD HL,#0x9000-(.endtp0-.tp0)
LD DE,#.endtp0-.tp0
CALL .mv_tiles ; Move tiles
LD BC,#.tp1
LD HL,#0x8000
LD DE,#.endtp1-.tp1
CALL .mv_tiles ; Move tiles
LD BC,#.tp2
LD HL,#0x8800
LD DE,#.endtp2-.tp2
CALL .mv_tiles ; Move tiles
LD BC,#.tp3
LD HL,#0x9000
LD DE,#.endtp3-.tp3
CALL .mv_tiles ; Move tiles
LD BC,#.bkg_tiles
CALL .set_btt
; Draw the frame in the window
LD BC,#.frame_tiles
LD DE,#0x0000/8 ; Place image at (0x00,0x00)
LD HL,#0x8050/8 ; Image size is 0x80 x 0x50
CALL .set_xy_wtt
; Draw the door in the window
LD BC,#.door1_tiles
LD DE,#0x1010/8 ; Place image at (0x10,0x10)
LD HL,#0x6030/8 ; Image size is 0x60 x 0x30
CALL .set_xy_wtt
LD A,#.CLOSED
LD (.doorstate),A
; Initialize background
XOR A ; A = 0
LD (.bposx),A
LDH (.SCROLLX),A
LD (.bposx+1),A
LD (.bposy),A
LDH (.SCROLLY),A
LD (.bposy+1),A
LD A,#-0x01
LD (.bspx),A
XOR A ; A = 0
LD (.bspx+1),A
XOR A ; A = 0
LD (.bspy),A
LD A,#0x80
LD (.bspy+1),A
; Initialize window
LD A,#.MAXWNDPOSX
LD (.wposx),A
LDH (.WNDPOSX),A
XOR A ; A = 0
LD (.wposx+1),A
LD A,#.MAXWNDPOSY
LD (.wposy),A
LDH (.WNDPOSY),A
XOR A ; A = 0
LD (.wposy+1),A
LD A,#-0x01
LD (.wspx),A
LD A,#0x80
LD (.wspx+1),A
LD A,#-0x01
LD (.wspy),A
LD A,#0xC0
LD (.wspy+1),A
; Initialize sprite
XOR A ; A = 0
LD (.sframe),A
LD C,#0x00 ; Sprite 0x00
LD D,#0x00
CALL .prop_sprite ; Default sprite properties
LD C,#0x01 ; Sprite 0x01
LD D,#0x00
CALL .prop_sprite ; Default sprite properties
LD A,#0x10
LD (.sposx),A
XOR A ; A = 0
LD (.sposx+1),A
LD A,#0x10
LD (.sposy),A
XOR A ; A = 0
LD (.sposy+1),A
XOR A ; A = 0
LD (.sspx),A
LD A,#0x40
LD (.sspx+1),A
XOR A ; A = 0
LD (.sspy),A
LD A,#0x40
LD (.sspy+1),A
CALL .tile_sprite ; Set sprite tiles
CALL .place_sprite ; Place sprites
LD A,#0b11100111 ; LCD Controller = On
LDH (.LCDCONT),A
EI ; Enable interrupts
1$:
LD A,(.time)
INC A
LD (.time),A
LD BC,#.DELAY
CALL .delay_ns
CALL .fade
CALL .door
CALL .scroll
CALL .animate_sprite
CALL .jpad
LD D,A
AND #.B ; Is B pressed ?
JP NZ,10$
LD A,D
AND #.A ; Is A pressed ?
JP NZ,20$
LD A,D
AND #.SELECT ; Is SELECT pressed ?
JR Z,2$
LD A,#.STARTFADE
LD (.color),A
2$:
LD A,D
AND #.START ; Is START pressed ?
JR Z,4$
LD A,(.doorstate)
CP #.CLOSED
JR NZ,3$
LD A,#.OPENING
LD (.doorstate),A
XOR A ; A = 0
LD (.doorpos),A
JR 4$
3$:
CP #.OPENED
JR NZ,4$
LD A,#.CLOSING
LD (.doorstate),A
LD A,#.NBDFRAMES
LD (.doorpos),A
4$:
LD A,D
AND #.UP ; Is UP pressed ?
JR Z,5$
LD B,#0x00 ; Load 0x0010 into BC
LD C,#0x10
LD A,(.sspy) ; Load speed into HL
LD H,A
LD A,(.sspy+1)
LD L,A
LD A,L ; Substract BC from HL
SUB C
LD (.sspy+1),A
LD A,H
SBC B
LD (.sspy),A ; Store new speed
JR 6$
5$:
LD A,D
AND #.DOWN ; Is DOWN pressed ?
JR Z,6$
LD B,#0x00 ; Load 0x0010 into BC
LD C,#0x10
LD A,(.sspy) ; Load speed into HL
LD H,A
LD A,(.sspy+1)
LD L,A
ADD HL,BC ; Add them
LD A,H ; Store new speed
LD (.sspy),A
LD A,L
LD (.sspy+1),A
6$:
LD A,D
AND #.LEFT ; Is LEFT pressed ?
JR Z,7$
LD B,#0x00 ; Load 0x0010 into BC
LD C,#0x10
LD A,(.sspx) ; Load speed into HL
LD H,A
LD A,(.sspx+1)
LD L,A
LD A,L ; Substract BC from HL
SUB C
LD (.sspx+1),A
LD A,H
SBC B
LD (.sspx),A ; Store new speed
JP 1$
7$:
LD A,D
AND #.RIGHT ; Is RIGHT pressed ?
JP Z,1$
LD B,#0x00 ; Load 0x0010 into BC
LD C,#0x10
LD A,(.sspx) ; Load speed into HL
LD H,A
LD A,(.sspx+1)
LD L,A
ADD HL,BC ; Add them
LD A,H ; Store new speed
LD (.sspx),A
LD A,L
LD (.sspx+1),A
JP 1$
10$:
LD A,D
AND #.UP ; Is UP pressed ?
JP Z,11$
LD B,#0x00 ; Load 0x0010 into BC
LD C,#0x10
LD A,(.bspy) ; Load speed into HL
LD H,A
LD A,(.bspy+1)
LD L,A
LD A,L ; Substract BC from HL
SUB C
LD (.bspy+1),A
LD A,H
SBC B
LD (.bspy),A ; Store new speed
JR 12$
11$:
LD A,D
AND #.DOWN ; Is DOWN pressed ?
JP Z,12$
LD B,#0x00 ; Load 0x0010 into BC
LD C,#0x10
LD A,(.bspy) ; Load speed into HL
LD H,A
LD A,(.bspy+1)
LD L,A
ADD HL,BC ; Add them
LD A,H ; Store new speed
LD (.bspy),A
LD A,L
LD (.bspy+1),A
12$:
LD A,D
AND #.LEFT ; Is LEFT pressed ?
JP Z,13$
LD B,#0x00 ; Load 0x0010 into BC
LD C,#0x10
LD A,(.bspx) ; Load speed into HL
LD H,A
LD A,(.bspx+1)
LD L,A
LD A,L ; Substract BC from HL
SUB C
LD (.bspx+1),A
LD A,H
SBC B
LD (.bspx),A ; Store new speed
JP 1$
13$:
LD A,D
AND #.RIGHT ; Is RIGHT pressed ?
JP Z,1$
LD B,#0x00 ; Load 0x0010 into BC
LD C,#0x10
LD A,(.bspx) ; Load speed into HL
LD H,A
LD A,(.bspx+1)
LD L,A
ADD HL,BC ; Add them
LD A,H ; Store new speed
LD (.bspx),A
LD A,L
LD (.bspx+1),A
JP 1$
20$:
LD A,D
AND #.UP ; Is UP pressed ?
JP Z,21$
LD B,#0x00 ; Load 0x0010 into BC
LD C,#0x10
LD A,(.wspy) ; Load speed into HL
LD H,A
LD A,(.wspy+1)
LD L,A
LD A,L ; Substract BC from HL
SUB C
LD (.wspy+1),A
LD A,H
SBC B
LD (.wspy),A ; Store new speed
JR 22$
21$:
LD A,D
AND #.DOWN ; Is DOWN pressed ?
JP Z,22$
LD B,#0x00 ; Load 0x0010 into BC
LD C,#0x10
LD A,(.wspy) ; Load speed into HL
LD H,A
LD A,(.wspy+1)
LD L,A
ADD HL,BC ; Add them
LD A,H ; Store new speed
LD (.wspy),A
LD A,L
LD (.wspy+1),A
22$:
LD A,D
AND #.LEFT ; Is LEFT pressed ?
JP Z,23$
LD B,#0x00 ; Load 0x0010 into BC
LD C,#0x10
LD A,(.wspx) ; Load speed into HL
LD H,A
LD A,(.wspx+1)
LD L,A
LD A,L ; Substract BC from HL
SUB C
LD (.wspx+1),A
LD A,H
SBC B
LD (.w